home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / CCDBMS.ZIP / DBARRAY.H < prev    next >
C/C++ Source or Header  |  1997-03-18  |  2KB  |  50 lines

  1. // =================================================================
  2. // Dbarray.cpp 
  3. // =================================================================
  4. // Harold Kasperink / John Dekker 
  5. // Dr. Dobb's Journal 1997
  6. // =================================================================
  7. // Multithreaded Database Array Singleton class
  8. // =================================================================
  9. #ifndef _DBARRAY_H_
  10. #define _DBARRAY_H_
  11.  
  12. #include "dbase.h"
  13. #define MAX_NR_DBASES    15
  14.  
  15. class CArrayDbase 
  16. {
  17. private:
  18.     static CArrayDbase *g_pDbArray;                    // Pointer to global database connection
  19.     static CMutex        g_mtxArray;                    // Mutex to make sure only one reserve/release at a time
  20.     CDbase*                m_pDbases[MAX_NR_DBASES];    // Array of database connections
  21.     int                    m_nNrDbases;                // Number of database connections
  22.     char*                m_pszUsr;                    // User name
  23.     char*                m_pszPsswd;                    // User password
  24.     char*                m_pszDb;                    // Database connect string
  25.     int                    m_nCurCon;                    // Current connection
  26.     int                    m_nDbUsage[MAX_NR_DBASES];    // Usage status indicator
  27.     boolean                m_bPrint;                    // Print usage flag
  28.  
  29. public:
  30.     CArrayDbase(int nNrConnections, const char *szUsr, const char *szPasswd, const char *szDB);
  31.     virtual ~CArrayDbase();
  32.     
  33.     // Get pointer to free database connection
  34.     // and reserve database connnection
  35.     static    CDbase*        ReserveDbase();
  36.     
  37.     // Release database connection
  38.     static    void        ReleaseDbase(CDbase &dbase);
  39.  
  40. private:
  41.     // Set connect information
  42.     void    ConnectInfo(const char *szUsr, const char *szPasswd, const char *szDB);
  43.     void    DeleteConnectInfo();
  44.     
  45.     static void            Lock();
  46.     static void            Unlock();
  47. };
  48.  
  49. #endif
  50.